import { message } from 'antd';
import api from '../../api';
export default {
  namespace: 'dataImportM',
  state: {
    list: [],
    data: {},
    dateAt: '',
  },

  effects: {
    *fetch({ payload, callback }, { call, put }) {
      const response = yield call(api.dataImport.queryDataImport, payload);
      if (response) {
        callback('success', response);

        yield put({
          type: 'save',
          payload: {
            list: response.data,
            dateAt: payload.importDate,
          },
        });
      } else {
        callback('fail');
      }
    },

    //编辑数据
    *updateTAdate({ payload, callback }, { call, put, select }) {
      const response = yield call(api.dataImport.updateTAdate, payload);
      if (response.success) {
        message.success('处理成功');

        callback('success', response);
      } else {
        message.error('处理失败');
        callback('fail', response);
      }
    },
    //提交数据--处理
    *submitData({ payload, callback }, { call, put, select }) {
      const response = yield call(api.dataImport.submitData, payload);

      if (response.success) {
        message.success('修改成功');

        callback('success', response);
      } else {
        message.error('修改失败');
        callback('fail', response);
      }
      return response;
    },
    //撤回数据--撤回
    *withdrawData({ payload, callback }, { call, put, select }) {
      const response = yield call(api.dataImport.withdrawData, payload);

      if (response.success) {
        message.success('撤回成功');

        callback('success', response);
      } else {
        message.error('撤回失败');
        callback('fail');
      }
      return response;
    },
    // *findDataImportById({ payload }, { call, put }) {
    //   const response = yield call(findDataImportById, payload.id);
    //   if (response) {
    //     yield put({
    //       type: 'save',
    //       payload: {
    //         data: response.data,
    //       },
    //     });
    //     return response.data;
    //   } else {
    //     message.error('查询失败');
    //   }
    // },
    // *updateShareAndFund({ payload }, { call, put }) {
    //   const response = yield call(updateShareAndFund, payload);
    //   if (response) {
    //     yield put({
    //       type: 'save',
    //       payload: {
    //         data: response.data,
    //       },
    //     });
    //     return response.data;
    //   } else {
    //     message.error('查询失败');
    //   }
    // },
    *deleteTAdate({ payload, callback }, { call, put, select }) {
      const response = yield call(api.dataImport.deleteTAdate, payload);
      if (response) {
        callback('success');
        message.success('删除成功');
      } else {
        callback('fail');
        message.error('删除失败');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
